import { useEffect, useState } from 'react'
// 名称必须以 use 开头，并且是小驼峰
export const useMouse = () => {
  const [position, setPosition] = useState({
    x: 0,
    y: 0,
  })
  useEffect(() => {
    const handleMouseMove = (e) => {
      setPosition({
        x: e.clientX + 50,
        y: e.clientY + 50,
      })
    }
    document.addEventListener('mousemove', handleMouseMove)
    return () => {
      // !解绑事件
      document.removeEventListener('mousemove', handleMouseMove)
    }
  }, [])
  return position
}
